/**
	Account model defines fields of the account.
 */
Ext.define('WEB.model.Account', {
    extend: 'Ext.data.Model',
    fields: [
		{name: 'id',            type: 'long', useNull: true            	},
		{name: 'firstName',     type: 'string'                     		},
		{name: 'lastName',   	type: 'string'                     		},
		{name: 'email',			type: 'string'                     		},
		{name: 'address',     	type: 'string'                     		},
		{name: 'city',     		type: 'string'                     		},
		{name: 'state',   		type: 'string'                          },
//		{name: 'version'  												},
//		{name: 'lastUpdate'												},
		{name: 'phoneNumber',   type: 'string'                          }

	],//fields

	proxy: {
		type: 'rest',
		url: 'accounts',
		reader: {
			type: 'json',
			root: 'data',
			successProperty: 'success'
		},
		writer: {
			type: 'json',
			successProperty: 'success'
		},
		listeners: {
			exception: function(proxy, res, oper, opts) {
				switch (oper.action) {
					case 'read':
						if (oper.success == false) {
							Ext.Msg.alert('Error', 'Failed to get a list of '+
							'accounts. Server returned an error.');
						}
						break;
					case 'create':
						if (oper.success == false) {
							var store = oper.records[0].store;
							store.remove(oper.records);
							Ext.Msg.alert('Error', 'Failed to create new '+
							'account. Server returned an error.');
						}
						break;
					case 'update':
						if (oper.success == false) {
							oper.records[0].set(oper.records[0].raw);
							Ext.Msg.alert('Error', 'Failed to update account. '+
							'Server returned an error.');
						}
						break;
					case 'destroy':
						if (oper.success == false) {
							Ext.Msg.alert('Error', 'Failed to delete account. '+
							'Server returned an error.');
						}
						break;
					default:
						Ext.Msg.alert('Error', 'An unexpected error occured '+
						'while performing '+oper.action+' operation. Server '+
						'is saying: '+res.responseText);
				}//switch
			}//exception
		}//listeners
	}//proxy
});